import {createI18n} from 'vue-i18n';
import zh from 'element-plus/lib/locale/lang/zh-cn'
import en from 'element-plus/lib/locale/lang/en'
import {reactive} from "vue";

export const messages = {
    en: {
        header: {
            instanceStatus: 'Instance Status',
            eventManagement: 'Event Management',
            configurationManagement: 'Configuration Management',
            monitoring: 'Monitoring',
            configuration: 'Configuration',
        },
        instanceView: {
            event: 'Event',
            instanceStatus: 'Instance Status',
            application: 'Application',
            appName: 'Application',
            service: 'Service',
            artifactName: 'Artifact',
            processId: 'Process ID',
            DynamicInstall: 'Dynamic Install',
            uninstallPlugin: 'Uninstall Plugin',
            installPlugin: 'Install Plugin',
            uninstallAgent: 'Uninstall Agent',
            updatePlugin: 'Update Plugin',
            updateAgent: 'Update Agent',
            installExternalAgent: 'Install External Agent',
            commandTypePlaceholder: 'Please select The command type',
            agentPathPlaceholder: 'Please input the Agent path',
            pluginNamePlaceholder: 'Please enter the plugin name',
            externalAgentPathPlaceholder: 'Please input the Agent path',
            externalAgentNamePlaceholder: 'Please enter the Agent name',
            paramPlaceholder: 'Please input the parameter information',
            commandTypeNotice: 'Supported command types for hot plugging functionality',
            agentPathNotice: 'Fill in the absolute path of the parent directory of sermant-agent.jar here(If empty, use the original agent path)',
            externalAgentPathNotice: 'Absolute path of the directory where the Agent file is located',
            pluginNameNotice: 'Names of plugins to update or uninstall, separated by commas for multiple plugins',
            externalAgentNameNotice: 'Give the name of your Agent, input OTEL for OpenTelemetry(specially supported)',
            paramNotice: 'Configuration information specified when updating plugins or Sermant, in the format xxx=xxx,xxx=xxx',
            commandType: 'Command Type',
            pluginName: 'Plugin Name',
            agentPath: 'Agent Path',
            externalAgentName: 'Agent Name',
            param: 'Param',
            instance: 'Instance',
            version: 'Version',
            status: 'Status',
            instanceID: 'Instance ID',
            heartbeat: 'Heartbeat',
            plugin: 'Plugin',
            externalAgent: 'External Agent',
            successfullyObtainedInstances: 'Successfully obtained instances',
            failedToObtainInstances: 'Failed to obtain instances',
            notSelectInstance: 'Please select the instance for hot plugging first',
            success: "Hot plugging command issued successfully",
            failure: "Hot plugging command issued failed",
            operation: 'Operation',
            hotPlugging: 'Hot Plugging',
            inputParam: 'Please input parameter information',
            view: 'View Result',
            yes: 'Yes',
            no: 'No',
            confirm: 'Confirm',
            cancel: 'Cancel',
        },
        eventViews: {
            instance: 'Instance',
            eventMonitoring: 'Event Monitoring',
            emergencyEvent: 'Emergency',
            importantEvent: 'Important',
            normalEvent: 'Normal',
            service: 'Service',
            startTime: 'Start Time',
            endTime: 'End Time',
            autoRefresh: 'Auto Refresh',
            logDetail: 'Log Detail',
            logLevel: 'Log Level',
            logInformation: 'Log Information',
            logRelatedClass: 'Log Related Class',
            logRelatedMethod: 'Log Related Method',
            logLine: 'Log Line',
            threadID: 'Thread ID',
            exceptionType: 'Exception Type',
            eventDetail: 'Event Detail',
            description: 'Description',
            event: 'Event',
            level: 'Level',
            emergency: 'Emergency',
            important: 'Important',
            normal: 'Normal',
            type: 'Type',
            log: 'Log',
            operation: 'Operation',
            governance: 'Governance',
            area: 'Area',
            time: 'Time',
            lastHalfHour: 'Last Half Hour',
            lastHour: 'Last Hour',
            lastDay: 'Last Day',
            lastThreeDays: 'Last Three Days',
            lastWeek: 'Last Week',
            enableAutoRefresh: 'Enable Auto Refresh',
            disableAutoRefresh: 'Disable Auto Refresh',
            agentStartup: 'Agent Startup',
            agentShutdown: 'Agent Shutdown',
            enhanceSuccess: 'Enhance Success',
            enhanceFail: 'Enhance Fail',
            serviceStop: 'Service Stop',
            serviceStart: 'Service Start',
            pluginLoad: 'Plugin Install',
            warningLog: 'Warning Log',
            errorLog: 'Error Log',
            rateLimiting: 'RateLimiting',
            circuitBreaker: 'CircuitBreaker',
            adaptiveOverloadProtection: "Adaptive Overload Protection",
            gracefulOnlineBegin: "Graceful Online Begin",
            gracefulOnlineEnd: "Graceful Online End",
            gracefulOfflineBegin: "Graceful Offline Begin",
            gracefulOfflineEnd: "Graceful Offline End",
            routerRuleRefresh: "Router Rule Refresh",
            sameTagRuleMatch: "Same Tag Rule Match",
            sameTagRuleMismatch: "Same Tag Rule Mismatch",
            instanceRemoval: "Instance Removal",
            instanceRecovery: "Instance Recovery",
            springbootRegistry: "Springboot Registry",
            springbootUnRegistry: "Springboot UnRegistry",
            springbootGrayConfigRefresh: "Springboot Gray Config Refresh",
            successfullyObtainedEvents: "Successfully obtained events",
            failedToObtainEvents: "Failed to obtain events",
            hotPlugging: 'Hot Plugging',
            instanceId: 'Instance Id',
            pluginInstall: 'Plugin Install',
            pluginUninstall: 'Plugin Uninstall',
            pluginUpdate: 'Plugin Update',
            externalAgentInstall: 'External Agent Install',
            otelStart: 'OTEL Agent Start',
        },
        eventConfigView: {
            event: 'Event',
            configuration: 'Configuration',
            webHookConfiguration: 'WebHook Configuration',
            switch: 'Switch',
            type: 'Type',
            address: 'Address',
            operation: 'Operation',
            edit: 'Edit',
            testConnection: 'Test Connection',
            feiShu: 'FeiShu',
            dingTalk: 'Dingtalk',
            successfullyObtainedWebhookConfiguration: 'Successfully obtained webhook configuration',
            failedToObtainWebHookConfiguration: 'Failed to obtain WebHook configuration',
            success: 'Success',
            failed: 'Failed',
            successfullyInitiatedWebHookTest: 'Successfully initiated WebHook test',
            failedToInitiateWebHookTest: 'Failed to initiate WebHook test',
        },
        configView: {
            instance: 'Instance',
            configurationManagement: 'Configuration Management',
            configurationCenterInformation: 'Configuration Center Information',
            type: 'Type',
            address: 'Address',
            user: 'User',
            configurationInformation: 'Configuration Information',
            plugin: 'Plugin',
            configType: 'Type',
            inputProjectName: 'Input project name',
            project: 'Project',
            inputApplicationName: 'Input application name',
            application: 'Application',
            service: 'Service',
            inputServiceName: 'Input service name',
            environment: 'Environment',
            inputEnvironmentName: 'Input environment name',
            zone: 'Zone',
            inputZoneName: 'Input zone name',
            inputGroup: 'Input group',
            inputKey: 'Input key',
            operation: 'Operation',
            view: 'View',
            areYouSureToDeleteTheCurrentConfiguration: 'Are you sure to delete the current configuration?',
            delete: 'Delete',
            yes: 'Yes',
            no: 'No',
            create: 'Create',
            theProjectCannotBeEmpty: 'The project cannot be empty',
            theGroupCannotBeEmpty: 'The group cannot be empty',
            successfullyObtainedConfiguration: 'Successfully obtained configuration',
            failedObtainedConfiguration: 'Failed to obtain configuration',
            successfullyDeletedConfiguration: 'Successfully deleted configuration',
            failedDeletedConfiguration: 'Failed to delete configuration',
        },
        common: {
            success: 'Success',
            unableToConnectToConfigurationCenter: 'Unable to connect to configuration center',
            failedToObtainConfiguration: 'Failed to obtain configuration',
            configurationAlreadyExists: 'Configuration already exists',
            failedToCreateConfiguration: 'Failed to create configuration',
            failedToPublishConfiguration: 'Failed to publish configuration',
            failedToDeleteConfiguration: 'Failed to delete configuration',
            configurationDoesNotExist: 'Configuration does not exist',
            missingRequestParameters: 'Missing request parameters',
            failedToObtainTemplate: 'Failed to obtain template',
            failedToRequest: 'Failed to request',
            notEnable: 'Dynamic configuration switch not turned on',
            router: 'router',
            springbootRegistry: 'springboot-registry',
            serviceRegistry: 'service-registry',
            flowcontrol: 'flowcontrol',
            removal: 'service-removal',
            loadbalancer: 'loadbalancer',
            tagTransmission: 'tag-transmission',
            mqConsumeProhibition: 'mq-consume-prohibition',
            databaseWriteProhibition: 'database-write-prohibition',
            other: 'other',
            common: 'common',
        },
        configInfo: {
            configurationManagement: 'Configuration Management',
            configurationDetail: 'Configuration Detail',
            pluginInformation: 'Plugin Information',
            type: 'Type',
            selectPlugin: 'Select plugin',
            ruleInformation: 'Rule Information',
            ruleType: 'Rule Type',
            selectRuleType: 'Select rule type',
            ruleTypeSupportedInPlugin: 'Rule type supported in plugin',
            inputSceneName: 'Input scene name',
            sceneName: 'Scene Name',
            flowcontrolRuleNotice: 'The flow control rule will only take effect when the scene name matches the traffic matching rule',
            loadbalancerRuleNotice: 'The load balancing strategy will only take effect when the scenario of traffic tagging and load balancing strategy is consistent',
            inputProjectName: 'Input project name',
            projectNotice: 'This configuration corresponds to the service.meta.project in the sermant configuration file',
            inputApplicationName: 'Input application name',
            applicationNotice: 'This configuration corresponds to the service.meta.application in the sermant configuration file',
            inputServiceNameOrEmpty: 'Input service name (When empty, it is a global configuration)',
            metaServiceNotice: 'This configuration corresponds to the service.meta.service in the sermant configuration file',
            inputEnvironmentName: 'Input environment name',
            environmentNotice: 'This configuration corresponds to the service.meta.environment in the sermant configuration file',
            inputZoneName: 'Input zone name',
            zoneNotice: 'This configuration corresponds to the service.meta.zone in the sermant configuration file',
            serviceInformation: 'Service Information',
            inputServiceName: 'Input service name',
            serviceNotice: 'The name of the microservice is determined by the dubbo.application.name and spring.application.name in the microservice configuration file',
            configurationInformation: 'Configuration Information',
            inputConfigurationGroup: 'Input configuration group',
            configurationNotice: 'Automatically generated when configuring the Sermant native plugin configuration, no modification required',
            inputConfigurationName: ' Input configuration name',
            configurationContent: 'Configuration Content',
            inputConfigurationContent: 'Input configuration content',
            configurationContentNotice: 'The native Sermant plugin requires the use of yaml format',
            trafficMatchingRule: 'Traffic Matching Rule',
            rateLimitingRule: 'Rate Limiting Rule',
            circuitBreakerRule: 'Circuit Breaker Rule',
            bulkheadRule: 'Bulkhead Rule',
            faultInjectionRule: 'Fault Injection Rule',
            retryRule: 'Retry Rule',
            systemLevelFlowControl: 'System Level Flow Control',
            trafficTaggingRule: 'Traffic Tagging Rule',
            loadBalancingRule: 'Load Balancing Rule',
            successfullyCreatedConfiguration: 'Successfully created configuration',
            failedToCreateConfiguration: 'Failed to create configuration',
            successfullyUpdatedConfiguration: 'Successfully updated configuration',
            failedToUpdateConfiguration: 'Failed to update configuration',
            failedToObtainConfiguration: 'Failed to obtain configuration',
            submit: 'Submit',
            configElement: 'Configuration Element Information',
            configRule: 'Configuration Item Generation Rules',
            groupRule: 'Group Rules',
            keyRule: 'Key Rules',
            groupRulePlaceholder: 'Please select the generation rule for group',
            keyRulePlaceholder: 'Please select the generation rule for key',
            groupRuleNotice: 'Generation rule for group',
            keyRuleNotice: 'Generation rule for key',
        }
    },
    zh: {
        header: {
            instanceStatus: '实例状态',
            eventManagement: '事件管理',
            configurationManagement: '配置管理',
            monitoring: '监测',
            configuration: '配置',
        },
        instanceView: {
            event: '事件',
            instanceStatus: '实例状态',
            application: '应用',
            appName: '应用',
            service: '服务',
            artifactName: 'Artifact',
            processId: '进程ID',
            DynamicInstall: '动态安装',
            uninstallPlugin: '卸载插件',
            installPlugin: '安装插件',
            uninstallAgent: '卸载Agent',
            updatePlugin: '升级插件',
            updateAgent: '升级Agent',
            installExternalAgent: '安装外部Agent',
            commandTypePlaceholder: '请选择命令类型',
            agentPathPlaceholder: '请输入Agent路径',
            pluginNamePlaceholder: '请输入插件名称',
            externalAgentPathPlaceholder: '请输入Agent路径',
            externalAgentNamePlaceholder: '请输入Agent名称',
            paramPlaceholder: '请输入参数信息',
            commandTypeNotice: '动态挂载功能的支持的命令类型',
            agentPathNotice: '此处填写sermant-agent.jar的上级目录的绝对路径(如果不填则使用原有Agent路径)',
            externalAgentPathNotice: 'Agent文件所在目录的绝对路径',
            pluginNameNotice: '更新或者卸载的插件名称，多个插件时用,隔开',
            externalAgentNameNotice: '定义您的Agent的名称，如使用OpenTelemetry请输入OTEL(已特别支持)',
            paramNotice: '更新插件或者Sermant时指定的配置信息，格式为xxx=xxx,xxx=xxx',
            commandType: '命令类型',
            pluginName: '插件名称',
            agentPath: 'Agent路径',
            externalAgentName: 'Agent名称',
            param: '参数',
            instance: '实例',
            version: '版本',
            status: '状态',
            instanceID: '实例ID',
            heartbeat: '心跳时间',
            plugin: '插件',
            externalAgent: '外部Agent',
            successfullyObtainedInstances: '获取实例数据成功',
            failedToObtainInstances: '获取实例数据失败',
            notSelectInstance: '请先选择动态挂载的实例',
            success: "动态挂载指令发布成功",
            failure: "动态挂载指令发布失败",
            operation: '操作',
            hotPlugging: '热插拔',
            inputParam: '请输入参数信息',
            view: '查看结果',
            yes: '是',
            no: '否',
            confirm: '确认',
            cancel: '取消',
        },
        eventViews: {
            instance: '实例',
            eventMonitoring: '事件监测',
            emergencyEvent: '紧急事件',
            importantEvent: '重要事件',
            normalEvent: '一般事件',
            service: '服务',
            startTime: '开始时间',
            endTime: '结束时间',
            autoRefresh: '自动刷新',
            logDetail: '日志详情',
            logLevel: '日志级别',
            logInformation: '日志信息',
            logRelatedClass: '日志触发类',
            logRelatedMethod: '日志触发方法',
            logLine: '日志触发行号',
            threadID: '线程ID',
            exceptionType: '异常类型',
            eventDetail: '事件详情',
            description: '描述信息',
            event: '事件',
            level: '事件级别',
            emergency: '紧急',
            important: '重要',
            normal: '一般',
            type: '事件类型',
            log: '日志',
            operation: '运行',
            governance: '治理',
            area: '事件区域',
            time: '上报时间',
            lastHalfHour: '最近半小时',
            lastHour: '最近一小时',
            lastDay: '最近一天',
            lastThreeDays: '最近三天',
            lastWeek: '最近一周',
            enableAutoRefresh: '开启自动刷新',
            disableAutoRefresh: '关闭自动刷新',
            agentStartup: 'Agent启动',
            agentShutdown: 'Agent停止',
            enhanceSuccess: '增强成功',
            enhanceFail: '增强失败',
            serviceStop: '服务停止',
            serviceStart: '服务启动',
            pluginLoad: '插件加载',
            warningLog: '警告日志',
            errorLog: '错误日志',
            rateLimiting: '限流',
            circuitBreaker: '熔断',
            adaptiveOverloadProtection: "自适应过载保护",
            gracefulOnlineBegin: "无损上线开始",
            gracefulOnlineEnd: "无损上线结束",
            gracefulOfflineBegin: "无损下线开始",
            gracefulOfflineEnd: "无损下线结束",
            routerRuleRefresh: "路由插件规则刷新",
            sameTagRuleMatch: "同标签优先规则匹配成功",
            sameTagRuleMismatch: "同标签优先规则匹配失败",
            instanceRemoval: "实例摘除",
            instanceRecovery: "实例恢复",
            springbootRegistry: "springboot服务注册",
            springbootUnRegistry: "springboot服务移除注册",
            springbootGrayConfigRefresh: "springboot注册插件灰度规则刷新",
            successfullyObtainedEvents: "获取事件成功",
            failedToObtainEvents: "获取事件失败",
            hotPlugging: '热插拔',
            instanceId: '实例Id',
            pluginInstall: '插件安装',
            pluginUninstall: '插件卸载',
            pluginUpdate: '插件更新',
            externalAgentInstall: '安装外部Agent',
            otelStart: 'OTEL Agent启动',
        },
        eventConfigView: {
            event: '事件',
            configuration: '事件配置',
            webHookConfiguration: 'WebHook 配置',
            switch: '开关',
            type: '类型',
            address: '地址',
            operation: '操作',
            edit: '编辑',
            testConnection: '测试连接',
            feiShu: '飞书',
            dingTalk: '钉钉',
            successfullyObtainedWebhookConfiguration: '获取WebHook配置成功',
            failedToObtainWebHookConfiguration: '获取WebHook配置失败',
            success: '设置成功',
            failed: '设置失败',
            successfullyInitiatedWebHookTest: '发起WebHook测试成功',
            failedToInitiateWebHookTest: '发起WebHook测试失败',
        },
        configView: {
            instance: '实例',
            configurationManagement: '配置管理',
            configurationCenterInformation: '配置中心信息',
            type: '配置中心类型',
            address: '配置中心地址',
            user: '用户名称',
            configurationInformation: '配置信息',
            plugin: '插件类型',
            configType: '配置类型',
            inputProjectName: '请输入命名空间',
            project: '命名空间',
            inputApplicationName: '请输入应用名称',
            application: '应用名称',
            service: '服务名称',
            inputServiceName: '请输入服务名称',
            environment: '环境名称',
            inputEnvironmentName: '请输入环境名称',
            zone: '区域名称',
            inputZoneName: '请输入区域名称',
            inputGroup: '请输入group',
            inputKey: '请输入key',
            operation: '操作类型',
            view: '查看',
            areYouSureToDeleteTheCurrentConfiguration: '是否确认删除当前配置项？',
            delete: '删除',
            yes: '是',
            no: '否',
            create: '新增',
            theProjectCannotBeEmpty: '命名空间不能为空',
            theGroupCannotBeEmpty: 'group不能为空',
            successfullyObtainedConfiguration: '获取配置成功',
            failedObtainedConfiguration: '获取配置失败',
            successfullyDeletedConfiguration: '删除配置成功',
            failedDeletedConfiguration: '删除配置失败',
        },
        common: {
            success: '成功',
            unableToConnectToConfigurationCenter: '无法连接配置中心',
            failedToObtainConfiguration: '配置查询失败',
            configurationAlreadyExists: '配置已存在',
            failedToCreateConfiguration: '新增配置失败',
            failedToPublishConfiguration: '发布配置失败',
            failedToDeleteConfiguration: '删除配置失败',
            configurationDoesNotExist: '配置不存在',
            missingRequestParameters: '缺少请求参数',
            failedToObtainTemplate: '获取模板失败',
            failedToRequest: '请求失败',
            notEnable: '动态配置开关未开启',
            router: '路由插件',
            springbootRegistry: 'springboot注册插件',
            serviceRegistry: '注册迁移插件',
            flowcontrol: '流控插件',
            removal: '离群实例摘除插件',
            loadbalancer: '负载均衡插件',
            tagTransmission: '标签透传插件',
            mqConsumeProhibition: '消息队列禁止消费插件',
            databaseWriteProhibition: '数据库禁写插件',
            other: '其他',
            common: '通用',
        },
        configInfo: {
            configurationManagement: '配置管理',
            configurationDetail: '配置详情',
            pluginInformation: '插件配置信息',
            type: '插件类型',
            selectPlugin: '请选择插件类型',
            ruleInformation: '规则信息',
            ruleType: '规则类型',
            selectRuleType: '请选择规则类型',
            ruleTypeSupportedInPlugin: '插件支持的规则类型',
            inputSceneName: '请输入规则场景名称',
            sceneName: '规则场景名称',
            flowcontrolRuleNotice: '流量匹配和具体流控规则的场景名称一致时流控规则才会生效',
            loadbalancerRuleNotice: '流量标记和负载均衡策略的场景一致时负载均衡策略生效',
            inputProjectName: '请输入命名空间',
            projectNotice: '该配置对应sermant配置文件中的service.meta.project',
            inputApplicationName: '请输入应用名称',
            applicationNotice: '该配置对应sermant配置文件中的service.meta.application',
            inputServiceNameOrEmpty: '请输入服务名称，为空时下发全局配置',
            metaServiceNotice: '该配置对应sermant配置文件中的service.meta.service',
            inputEnvironmentName: '请输入环境名称',
            environmentNotice: '该配置对应sermant配置文件中的service.meta.environment',
            inputZoneName: '请输入区域名称',
            zoneNotice: '该配置对应sermant配置文件中的service.meta.zone',
            serviceInformation: '服务信息',
            inputServiceName: '请输入服务名称',
            serviceNotice: '微服务的名称，由微服务配置文件的dubbo.application.name、spring.applicaton.name确定',
            configurationInformation: '配置项信息',
            inputConfigurationGroup: '请输入配置项的group',
            configurationNotice: '配置sermant原生插件配置时，自动生成，无需修改',
            inputConfigurationName: '请输入配置项名称',
            configurationContent: '配置内容',
            inputConfigurationContent: '请输入配置内容',
            configurationContentNotice: 'sermant原生插件需使用yaml格式',
            trafficMatchingRule: '流量匹配规则',
            rateLimitingRule: '限流规则',
            circuitBreakerRule: '熔断规则',
            bulkheadRule: '隔离规则',
            faultInjectionRule: '错误注入',
            retryRule: '重试',
            systemLevelFlowControl: '系统级流控',
            trafficTaggingRule: '流量标记规则',
            loadBalancingRule: '负载均衡规则',
            successfullyCreatedConfiguration: '新增配置成功',
            failedToCreateConfiguration: '新增配置失败',
            successfullyUpdatedConfiguration: '更新配置成功',
            failedToUpdateConfiguration: '更新配置失败',
            failedToObtainConfiguration: '获取配置失败',
            submit: '提交',
            configElement: '配置元素信息',
            configRule: '配置项的生成规则',
            groupRule: 'Group规则',
            keyRule: 'key规则',
            groupRulePlaceholder: '请选择group的生成规则',
            keyRulePlaceholder: '请选择key的生成规则',
            groupRuleNotice: 'group的生成规则',
            keyRuleNotice: 'key的生成规则',
        }
    },
};

const getSavedLanguage = () => {
    return localStorage.getItem('language') || 'zh'; // 默认语言为英语
};

const i18n = createI18n({
    locale: getSavedLanguage(),
    fallbackLocale: getSavedLanguage(),
    messages,
});

export const localeLanguage = reactive({
    value: getSavedLanguage() === 'zh' ? zh : en,
    language: getSavedLanguage()
});

export function switchLocale(lang: ('zh' | 'en')) {
    if (lang === 'en') {
        localeLanguage.value = en;
    } else {
        localeLanguage.value = zh;
    }
    localeLanguage.language = lang;
    i18n.global.locale = lang;
    localStorage.setItem('language', lang);
}

export default i18n;
